package com.itheima.泛型.sort.Comparable;

/**
 * @Author 王加鑫
 * @Date 2021/5/14 12:40
 * @Version 1.0
 */
public class Person implements Comparable<Person> {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }


    @Override
    public int compareTo(Person o) {
       //年龄降序,姓名升序
        //int res = o.age - this.age;
        int res = o.name.length() - this.name.length();

        /*//先比较姓名的长度,再比较姓名的字典顺序
        res = res == 0 ? res = o.age - this.age == 0? this.name.length() - o.name.length() : res : res ;*/
        return res;
    }
}
